import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

import org.apache.commons.lang.time.DateUtils;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsDateJsonBeanProcessor;


public class JsonDate {
	 public static void main(String[] args) {
	        // json-lib默认不支持java.sql.Date的序列化，要序列化自己的类，实现一个BeanProcessor处理即可
	        JsDateJsonBeanProcessor beanProcessor = new JsDateJsonBeanProcessor();
	        java.sql.Date d = new java.sql.Date(System.currentTimeMillis());

	        // 直接序列化
	        JsonConfig config = new JsonConfig();
	        JSONObject json = beanProcessor.processBean(d, config);
	        System.out.println(json.toString());

	        // 序列化含java.sql.Date作为属性值的bean
	        HashMap<String, Date> m = new HashMap<String, Date>();
	        m.put("date", d);
	        m.put("date2", new Date());
	        config.registerJsonBeanProcessor(java.util.Date.class, beanProcessor);
	        config.registerJsonBeanProcessor(java.sql.Date.class, beanProcessor);
	        json = JSONObject.fromObject(m, config);
	        System.out.println(json.toString());
	        
	        String test="1212";
	        
	        String[] result=test.split(",");
	        System.out.println(">>"+result.length);
	    	SimpleDateFormat myFmt=new SimpleDateFormat("yyyyMMddHHmmss.SS");
	        System.out.println(myFmt.format(DateUtils.truncate(new Date(), Calendar.MILLISECOND)));
	        System.out.println(myFmt.format(DateUtils.truncate(new Date(), Calendar.SECOND)));
	    }
}
